package com.gnerv.business.test.service.impl;

import com.gnerv.business.test.service.ChromeService;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Service
public class ChromeServiceImpl implements ChromeService {

    @Override
    public void test() {

        String path = this.getClass().getClassLoader().getResource("static/driver/chromedriver.exe").getPath();
        System.setProperty("webdriver.chrome.driver", path);

        WebDriver chromeDriver = new ChromeDriver();

        //最大化窗口
        chromeDriver.manage().window().maximize();
        //设置隐性等待时间
        chromeDriver.manage().timeouts().implicitlyWait(8, TimeUnit.SECONDS);
        // get()打开一个站点
        chromeDriver.get("https://mail.163.com/");
        //getTitle()获取当前页面title的值
        System.out.println("当前打开页面的标题是： "+ chromeDriver.getTitle());
        //设置隐性等待时间
        chromeDriver.manage().timeouts().implicitlyWait(8, TimeUnit.SECONDS);


        WebElement xf = chromeDriver.findElement(By.xpath("//*[@id='loginDiv']/iframe"));
        chromeDriver.switchTo().frame(xf);


        WebElement tangramPsp10UserName = chromeDriver.findElement(By.name("email"));
        tangramPsp10UserName.sendKeys("");
        WebElement tangramPsp10Password = chromeDriver.findElement(By.name("password"));
        tangramPsp10Password.sendKeys("");
        WebElement tangramPsp10Submit = chromeDriver.findElement(By.id("dologin"));
        tangramPsp10Submit.click();

        //关闭并退出浏览器
        chromeDriver.quit();

    }
}
